﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;
using System.Text;
using System.Net.Http;
using System.Net.Http.Headers;

namespace iSufeMVC4.WebAPI.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// Json传递的测试
        /// </summary>
        /// <returns></returns>
        public ActionResult Test()
        {
            //var requestJson = JsonConvert.SerializeObject(new { startId = 1, itemcount = 3 });
            //HttpContent httpContent = new StringContent(requestJson);
            //httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            //var httpClient = new HttpClient();
            //var responseJson = httpClient
            //    .PostAsync("http://localhost:9000/api/demo/sitelist", httpContent)
            //    .Result.Content.ReadAsStringAsync()
            //    .Result;

            //var responseJson = new HttpClient()
            //    .PostAsJsonAsync(
            //        "http://api.isufe.org/api/talk/",
            //        new { userId = 0, courseId = 0, content = "test" })
            //    .Result.Content.ReadAsStringAsync().Result;
            var responseJson = new HttpClient()
                .PostAsJsonAsync(
                    "http://localhost:3771/api/talk/",
                    new { userId = 0, courseId = 0, content = "test" })
                .Result.Content.ReadAsStringAsync().Result;
            ViewBag.Content = responseJson;
            return View();
        }
    }
}
